from jili.trade.trade import trade
from jili.trade.constants import bs,openclose,status,ordertype,market
from jili.pos import fund,order,orderdetail,workingorder,position,positiondetail
class pos(trade):
    def __init__(self,brokerid,investid,password,broker_type="ctp"):
        super(pos, self).__init__(brokerid, investid, broker_type)
        self.ticks={}
        self.bars={}
        self.batbyticks={}
        return self.login(password)
    #submitorder(self,obj,bs,openclose,price,qty,marketcode,timekey=None,orderid="",oncall="")
    def buyopen(self, obj, qty, price,timekey=None):
        pos=self.pos["bypos"]
        marketcode=""
        if obj in pos.keys():
            pos_obj=pos[obj]

        return self.submitorder(obj, bs.buy, openclose.open, qty, price,timekey)

    def buyclose(self, obj, qty, price,timekey=None):
        return self.submitorder(obj, bs.buy, openclose.open, qty, price,timekey)

    def sellopen(self, obj, qty, price,timekey=None):
        return self.submitorder(obj, bs.sell, openclose.open, qty, price,timekey)
    def sellclose(self, obj, qty, price,timekey=None):
        return self.submitorder(obj, bs.sell, openclose.open, qty, price,timekey)
    """
    def ontick(self,tick):
        obj=tick["obj"]
        self.ticks[obj]=tick
        self.prices[obj]=tick["LastPrice"]
    def onbar(self,bar):
        obj=bar["obj"]
        self.bars[obj]=bar
        self.prices[obj]=bar["close"]
    def onbarbytick(self,btick):
        obj=btick["obj"]
        self.batbyticks[obj]=btick
        self.prices[obj] = btick["close"]
    """
